package com.example.book.crawler.task;

import com.example.book.crawler.entity.CrawlerCatalog;
import com.example.book.crawler.service.CrawlerCatalogService;
import com.example.book.in.entity.BookInfo;
import com.example.book.in.service.BookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Random;

@Component
public class BookCategoryTask {

    @Autowired
    private BookInfoService bookInfoService;


    @Scheduled(cron = "0 0/5 * * * ?")
    public void takeCatalog() {
        CrawlerCatalog catalog = null;
        List<BookInfo> list = bookInfoService.findListByLimit(10);
        for (BookInfo bi : list) {
            catalog = new CrawlerCatalog();
            catalog.setBookInfoId(bi.getId());
            catalog.setBookInfoStatus("0");
            catalog.setCrawlerUrl(bi.getRemarks());
            catalog.setIsCarriedOut("0");

            // 表示书籍已添加到抓取任务表
            bi.setBookStatus("0");

            bookInfoService.saveCCAndUpdate(catalog, bi);
        }
    }
}
